home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_01 / 1n01041a < prev    next >
Text File  |  1990-05-16  |  892b  |  32 lines

  1. /*
  2. **  Figure 4
  3. **
  4. **  Tee's all standard output to the printer.
  5. **
  6. **  Parameters: None
  7. **
  8. **  Returns:  0 if operation was successful.
  9. **           -1 if stdout or stdin is redirected.
  10. **
  11. **  Side effects: Flushes the keyboard buffer
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <conio.h>
  17. #include <io.h>
  18. #ifdef __ZTC__          /* Zortech C/C++ doesn't support ungetch()      */
  19. #include <mflconio.h>     /* Part of the MFLZT shareware library          */
  20. #endif
  21.  
  22. int cdecl prtoggle(void)
  23. {
  24.         if (!isatty(fileno(stdin)) || !isatty(fileno(stdout)))
  25.                 return -1;
  26.         while (kbhit())         /* Flush the keyboard buffer            */
  27.                 getch();
  28.         ungetch('P' - 64);      /* Stuff a Ctrl-P into the buffer       */
  29.         system("");             /* Let COMMAND.COM do the work          */
  30.         return 0;
  31. }
  32.